package cn.fl.institution.controller;

import cmm.comm.facade.framework.api.ISysCdMapApiService;
import cmm.comm.facade.framework.condition.SysCdMapDQueryCondition;
import cmm.comm.facade.framework.dto.SysCdMapDDTO;
import cmm.mid.core.framework.constant.tripartite.InterfaceConstants;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.customer.service.ICstNpBscInfoService;
import cn.fl.customer.vo.CstNpBscInfoVO;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.institution.api.IZgcbankInsApiService;
import cn.fl.institution.vo.BankInfo;
import cn.fl.project.api.IPrjCstAccInfoApiService;
import cn.fl.project.condition.PrjCstAccInfoQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.dto.PrjCstAccInfoDTO;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstAccInfoService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstAccInfoVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.SystemConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @Description: 项目基础信息表 控制层 中关村银行
 */
@Controller
@RequestMapping("/institution/zgcbank")
public class PrjBscInfoInsZgcbankController {
    private static final Logger logger = LoggerFactory.getLogger(PrjBscInfoInsZgcbankController.class);

    // 项目基础信息表
    @Autowired
    private IPrjBscInfoService prjBscInfoService;

    // 项目客户账户信息表
    @Autowired
    private IPrjCstAccInfoApiService prjCstAccInfoApiService;

    //项目客户基础信息表
    @Autowired
    private IPrjCstAccInfoService prjCstAccInfoService;

    @Autowired
    private IZgcbankInsApiService zgcbankInsApiService;

    // 自然人信息
    @Autowired
    private ICstNpBscInfoService cstNpBscInfoService;

    //代码映射服务
    @Autowired
    private ISysCdMapApiService sysCdMapApiService;


    /**
     * 获取验证码
     */
    @RequestMapping(value = "/getVerificationCodeForZgcbank.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object getVerificationCodeForZgcbank(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC,String changeTypeCd) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
        BaseLogUtils.info(logger, "getVerificationCodeForZgcbank", "中关村银行获取验证码 四要素信息： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC) + "changeTypeCd = " + changeTypeCd);
        // 开户银行
        if (StringUtils.isBlank(prjCstAccInfoQC.getBkCd()) || StringUtils.isBlank(prjCstAccInfoQC.getBkNm())) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入开户银行!");
            return result;
        }
        // 银行账号
        if (StringUtils.isBlank(prjCstAccInfoQC.getAccNo())) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入银行账号!");
            return result;
        }
        // 客户手机号
        if (StringUtils.isBlank(prjCstAccInfoQC.getMp())) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入手机号!");
            return result;
        }
        try {
            PrjCstAccInfoQueryCondition prjCstAccInfo = new PrjCstAccInfoQueryCondition();
            prjCstAccInfo.setPrjId(prjId);
            prjCstAccInfo.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfo.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK);
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfo);
            if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
                PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
                BaseLogUtils.info(logger, "getVerificationCodeForZgcbank", "中关村银行获取验证码 项目基本信息： prjBscInfoVO = " + JSONObject.toJSONString(prjCstAccInfo));
                prjCstAccInfoQC.setId(prjCstAccInfoVO.getId());
            }
            // 四要素验证
            prjCstAccInfoQC.setCertTypCd(DictionaryConstant.CODE_CERT_TYP_CD_0);
            prjCstAccInfoQC.setBkNo(prjCstAccInfoQC.getBkCd());
            prjCstAccInfoQC.setAccNm(prjCstAccInfoQC.getCstNm());
            prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK);
            BaseLogUtils.info(logger, "getVerificationCodeForZgcbank", "中关村银行获取验证码 页面提交的项目客户信息： " + JSONObject.toJSONString(prjCstAccInfoQC));
            DataResultDTO resultDTO = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
            // 判断四要素校验结果
            BaseLogUtils.info(logger, "getVerificationCodeForZgcbank", "中关村银行获取验证码 四要素验证结果 ： " + JSONObject.toJSONString(resultDTO));
            String chkRstCd = null, rstDesc = null;
            String bankCardType = null;
            if (resultDTO != null && StringUtils.isNotEmpty(resultDTO.getCode())
                    && Integer.valueOf(resultDTO.getCode()) != BaseConstant.IS_YESNO_YES) {
                chkRstCd = resultDTO.getCode();
                rstDesc = resultDTO.getInfo();
            } else if (resultDTO != null && resultDTO.getData() != null) {
                @SuppressWarnings("unchecked")
                Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
                chkRstCd = ckResMap.get("chkRstCd");
                rstDesc = ckResMap.get("rstDesc");
                bankCardType = ckResMap.get("bankCardType");
            }
            if (StringUtils.isBlank(chkRstCd) || !"1".equals(chkRstCd)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(rstDesc);
                return result;
            }
            if (!"0".equals(bankCardType)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("不支持此类银行卡，请更换为借记卡");
                return result;
            }
            // 发送验证码
            BaseLogUtils.info(logger, "getVerificationCodeForZgcbank", "中关村银行发送验证码接口调用信息:prjId=" + prjId + "---prjCstAccInfoQC=" + JSON.toJSONString(prjCstAccInfoQC));
            DataResultDTO dataResultDTO = this.zgcbankInsApiService.getVerificationCodeZgc(String.valueOf(prjCstAccInfoQC.getCstId()), String.valueOf(prjId), prjCstAccInfoQC.getBkNm(), prjCstAccInfoQC.getAccNo(), prjCstAccInfoQC.getCertNo(), prjCstAccInfoQC.getMp(),changeTypeCd);
            BaseLogUtils.info(logger, "getVerificationCodeForZgcbank", "中关村银行发送验证码接口调用结果:" + JSON.toJSONString(dataResultDTO));
            if (dataResultDTO != null) {
                result.setInfo(dataResultDTO.getInfo());
                if (dataResultDTO.getCode().equals(BaseConstant.IS_YESNO_YES_NM)) {
                    result.setSuccess(BaseConstant.IS_YESNO_YES);
                    result.setData(dataResultDTO.getData());
                } else {
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                }
            } else {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("验证码获取失败，请重新尝试！");
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "getVerificationCodeForZgcbank", "中关村银行获取验证码失败 " + ex.getMessage());
            ex.printStackTrace();
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("获取验证码失败!");
            BaseLogUtils.error(logger, "getVerificationCodeForZgcbank", "中关村银行获取验证码失败，系统异常 " + ex.getMessage());
            ex.printStackTrace();
        }
        return result;
    }

    //解绑 or 绑卡
    @RequestMapping(value = "/exchangeCardSave.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object exchangeCardSave(PrjCstAccInfoQueryCondition prjCstAccInfoQC, String verificationCode, String changeTypeCd) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功");
        BaseLogUtils.info(logger, "exchangeCardSave", "中关村换卡保存 项目客户账户信息Strat： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
        PrjCstAccInfoQueryCondition prjCstAccInfo = new PrjCstAccInfoQueryCondition();
        prjCstAccInfo.setPrjId(prjCstAccInfoQC.getPrjId());
        prjCstAccInfo.setIsDel(BaseConstant.IS_YESNO_NO);
        prjCstAccInfo.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK);
        List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfo);
        if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
            prjCstAccInfoQC.setId(prjCstAccInfoVO.getId());
            prjCstAccInfoQC.setAccNm(prjCstAccInfoVO.getAccNm());
        }
        // 设置证件类型
        prjCstAccInfoQC.setCertTypCd("01");
        prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK);

        try {
            // 四要素校验
            DataResultDTO resultDTO = this.prjCstAccInfoApiService.snVerifyModifyPrjAccInfo(prjCstAccInfoQC);
            String chkRstCd = null, rstDesc = null, bankCardType = null;

            if(null != resultDTO && null != resultDTO.getData()){
                @SuppressWarnings("unchecked")
                Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
                chkRstCd = ckResMap.get("chkRstCd");
                rstDesc = ckResMap.get("rstDesc");
                bankCardType = ckResMap.get("bankCardType");
                if(!"1".equals(chkRstCd)) {
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(rstDesc);
                    return result;
                }
                if (!"0".equals(bankCardType)){
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("不支持此类银行卡，请更换为借记卡");
                    return result;
                }
                BaseLogUtils.info(logger, "exchangeCardZGCSave", "检验结果,chkRstCd=" + chkRstCd);
                //验证返回结果成功
                if("1".equals(chkRstCd)) {
                    BaseLogUtils.info(logger, "exchangeCardZGCSave", "机构id： fundRasInsId = " + prjCstAccInfoQC.getInsId());
                    DataResultDTO dataResultDTO = this.zgcbankInsApiService.accountBindCard(prjCstAccInfoQC, verificationCode, changeTypeCd);
                    BaseLogUtils.info(logger, "exchangeCardZGCSave", "中关村换卡返回结果： dataResultDTO = " + JSONObject.toJSONString(dataResultDTO));
                    String msg = dataResultDTO != null && StringUtils.isNotEmpty(dataResultDTO.getInfo()) ? dataResultDTO.getInfo() : "操作失败，请核实";
                    if (dataResultDTO != null && dataResultDTO.getData() != null){
                        InterfaceConstants.AuditResult auditResult = (InterfaceConstants.AuditResult) dataResultDTO.getData();
                        if ("pass".equals(auditResult.key())){
                            if ("0".equals(changeTypeCd)){//解绑
                                prjCstAccInfoQC.setAccResCd("0");
                                prjCstAccInfoQC.setAccResMsg("解绑成功");
                            } else if ("1".equals(changeTypeCd)){//绑卡
                                prjCstAccInfoQC.setChkRstCd(chkRstCd);
                                prjCstAccInfoQC.setBankCardTypeCd(bankCardType);
                                prjCstAccInfoQC.setAccResCd("1");
                                prjCstAccInfoQC.setAccResMsg("绑卡成功");
                            }
                            BaseLogUtils.info(logger, "exchangeCardZGCSave", "换卡保存 项目客户账户信息End： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
                            DataResultDTO resultDTO1 = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
                            BaseLogUtils.info(logger, "exchangeCardZGCSave", "换卡保存 返回信息： resultDTO1 = " + JSONObject.toJSONString(resultDTO1));
                            result.setSuccess(BaseConstant.IS_YESNO_YES);
                            result.setInfo("操作成功");
                            return result;
                        }
                    }
                    result.setInfo(msg);
                } else {
                    result.setInfo("四要素校验未通过");
                }
            }
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            return result;
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "exchangeCardSave", "换卡保存失败 " + ex.getMessage());
            ex.printStackTrace();
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("保存失败!");
            BaseLogUtils.error(logger, "exchangeCardSave", "换卡保存失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        return result;
    }


    /**
     * 保存 项目客户信息
     */
    @RequestMapping(value = "/saveForZgcbank.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object saveForZgcbank(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
        BaseLogUtils.info(logger, "saveForZgcbank", "中关村银行立项保存 四要素信息： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
        // 开户银行
        if (StringUtils.isBlank(prjCstAccInfoQC.getBkCd()) || StringUtils.isBlank(prjCstAccInfoQC.getBkNm())) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入开户银行!");
            return result;
        }
        // 银行账号
        if (StringUtils.isBlank(prjCstAccInfoQC.getAccNo())) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入银行账号!");
            return result;
        }
        // 客户手机号
        if (StringUtils.isBlank(prjCstAccInfoQC.getMp())) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入手机号!");
            return result;
        }
        // 月收入
        if (StringUtils.isBlank(prjCstAccInfoQC.getMonthlyIncome())) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入月收入!");
            return result;
        }
        // 证件有效期(止)
        if (StringUtils.isBlank(prjCstAccInfoQC.getCertValidEDt())) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入证件有效期(止)!");
            return result;
        } else {
            if((!DateUtils.isDate(prjCstAccInfoQC.getCertValidEDt(), "yyyy-MM-dd"))
                    &&(!prjCstAccInfoQC.getCertValidEDt().equals(PropertiesCacheUtils.getProperty(SystemConstant.CHECK_DATE_LONG)))){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("请输入正确证件有效终止日期格式（yyyy-MM-dd 或 长期）！");
                return result;
            }
        }
        try {
            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK);
            PrjCstAccInfoVO prjCstAccInfo = null;
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
                prjCstAccInfo = prjCstAccInfoVOS.get(0);
            }
            BaseLogUtils.info(logger, "saveForZgcbank", "中关村银行立项保存 项目基本信息： prjBscInfoVO = " + JSONObject.toJSONString(prjCstAccInfo));
            // 是否需要开户
            boolean isNeedSign = true;
            if (null != prjCstAccInfo && null != prjCstAccInfo.getId()) {
                if (StringUtils.isNotBlank(prjCstAccInfo.getAccResCd()) && "1".equals(prjCstAccInfo.getAccResCd())) {
                    isNeedSign = false;
                }
                prjCstAccInfoQC.setId(prjCstAccInfo.getId());
                if (!(prjCstAccInfoQC.getCstNm().equals(prjCstAccInfo.getCstNm())
                        && prjCstAccInfoQC.getAccNo().equals(prjCstAccInfo.getAccNo())
                        && prjCstAccInfoQC.getMp().equals(prjCstAccInfo.getMp()))) {
                    // 四要素信息已修改
                    prjCstAccInfoQC.setAccResCd("0");
                    // 需要重新获取验证码
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "四要素信息已修改，请重新获取短信验证码!");
                }
            }
            BaseLogUtils.info(logger, "saveForZgcbank", "中关村银行立项保存 项目基本信息： isNeedSign = " + isNeedSign);
            if (isNeedSign) {
                // 短信验证码
                if (StringUtils.isBlank(prjCstAccInfoQC.getPhoneCode())) {
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("请输入短信验证码!");
                    return result;
                }
                CstNpBscInfoVO cstNpBscInfoVO = this.cstNpBscInfoService.selectById(prjCstAccInfoQC.getCstId());
                if (null != cstNpBscInfoVO) {
                    boolean flag = false;
                    // 月收入转为分
                    Long mrIncMoney = DecimalUtils.convertYuanToFen(Double.valueOf(prjCstAccInfoQC.getMonthlyIncome()));
                    // 月收入转换年收入
                    Double yrInc = DecimalUtils.mul(mrIncMoney.doubleValue(), 12d);
                    if (!Objects.equals(cstNpBscInfoVO.getYrInc().doubleValue(), yrInc)) {
                        flag = true;
                        cstNpBscInfoVO.setYrInc(yrInc.longValue());
                    }
                    if (!Objects.equals(cstNpBscInfoVO.getCertValidEDt(), prjCstAccInfoQC.getCertValidEDt())) {
                        flag = true;
                        cstNpBscInfoVO.setCertValidEDt(prjCstAccInfoQC.getCertValidEDt());
                    }
                    if (flag) {
                        cstNpBscInfoVO.setMdfTm(new Date());
                        cstNpBscInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                        BaseLogUtils.info(logger, "save", "修改自然人信息 cstNpBscInfoVO" + JSON.toJSONString(cstNpBscInfoVO), CurrentThreadContext.getCurrentUserName());
                        this.cstNpBscInfoService.modify(cstNpBscInfoVO);
                    }
                }
                prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK);
                // 保存项目客户信息，包含四要素验证
                prjCstAccInfoQC.setCertTypCd(DictionaryConstant.CODE_CERT_TYP_CD_0);
                prjCstAccInfoQC.setBkNo(prjCstAccInfoQC.getBkCd());
                prjCstAccInfoQC.setAccNm(prjCstAccInfoQC.getCstNm());

                BaseLogUtils.info(logger, "saveForZgcbank", "中关村银行立项保存 页面提交的项目客户信息： " + JSONObject.toJSONString(prjCstAccInfoQC));
                DataResultDTO resultDTO = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
                // 判断四要素校验结果
                BaseLogUtils.info(logger, "saveForZgcbank", "中关村银行立项保存 四要素验证结果 ： " + JSONObject.toJSONString(resultDTO));

                String chkRstCd = null, rstDesc = null;
                String bankCardType = null;
                Map<String, String> ckResMap = null;
                if (resultDTO != null) {
                    if ("0".equals(resultDTO.getCode())) {
                        result.setSuccess(BaseConstant.IS_YESNO_NO);
                        result.setInfo(rstDesc);
                        return result;
                    }
                    if (resultDTO.getData() != null) {
                        ckResMap = (Map<String, String>) resultDTO.getData();
                        chkRstCd = ckResMap.get("chkRstCd");
                        rstDesc = ckResMap.get("rstDesc");
                        bankCardType = ckResMap.get("bankCardType");

                        //验证返回结果成功
                        if (!"1".equals(chkRstCd)) {
                            result.setSuccess(BaseConstant.IS_YESNO_NO);
                            result.setInfo(rstDesc);
                            return result;
                        }
                        if (!"0".equals(bankCardType)) {
                            result.setSuccess(BaseConstant.IS_YESNO_NO);
                            result.setInfo("不支持此类银行卡，请更换为借记卡");
                            return result;
                        }
                    }
                } else {
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("四要素验证返回空");
                    return result;
                }
                result.setInfo("客户信息保存成功！");
                // 开户
                BaseLogUtils.info(logger, "saveForZgcbank", "中关村银行发送验证码接口调用信息:prjId=" + prjId + "---prjCstAccInfoQC=" + JSON.toJSONString(prjCstAccInfoQC));
                DataResultDTO dataResultDTO = this.zgcbankInsApiService.createAccount(String.valueOf(prjCstAccInfoQC.getCstId()), String.valueOf(prjId), prjCstAccInfoQC.getBkNm(), prjCstAccInfoQC.getAccNo(), prjCstAccInfoQC.getCertNo(), prjCstAccInfoQC.getMp(), prjCstAccInfoQC.getPhoneCode());
                BaseLogUtils.info(logger, "saveForZgcbank", "中关村银行开户接口调用结果:" + JSON.toJSONString(dataResultDTO));
                if (dataResultDTO != null) {
                    if (dataResultDTO.getCode().equals(BaseConstant.IS_YESNO_YES_NM)) {
                        // 更新数据
                        if (prjCstAccInfoQC.getId() == null || prjCstAccInfoQC.getId().equals("1")) {
                            if (ckResMap != null && StringUtils.isNotBlank(ckResMap.get("prjCstId"))) {
                                try {
                                    // 尝试插入主键，不影响代后续操作
                                    prjCstAccInfoQC.setId(Long.parseLong(ckResMap.get("prjCstId")));
                                } catch (Exception e) {
                                }
                            }
                        }
                        prjCstAccInfoQC.setAccResCd("1");
                        prjCstAccInfoQC.setAccResMsg("开户成功");
                        BaseLogUtils.info(logger, "saveForZgcbank", "开户保存 项目客户账户信息End： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
                        DataResultDTO resultDTO1 = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
                        if (null != resultDTO1) {
                            @SuppressWarnings("unchecked")
                            Map<String, String> ckResMap1 = (Map<String, String>) resultDTO.getData();
                            chkRstCd = ckResMap1.get("chkRstCd");
                            rstDesc = ckResMap1.get("rstDesc");
                            if (chkRstCd.equals("1")) {
                                //更新校验成功
                                PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjCstAccInfo.getPrjId()));
                                result.setSuccess(BaseConstant.IS_YESNO_YES);
                                String code = "";
                                if (null != dataResultDTO.getData()) {
                                    Map<String, Object> dataMap = (Map<String, Object>) dataResultDTO.getData();
                                    code = (null == dataMap.get("code") ? "" : dataMap.get("code").toString());
                                }
                                result.setInfo("开户成功，客户在" + prjBscInfoVO.getFundRasInsNm() + "还款银行卡已绑卡" + code);
                            } else {
                                result.setSuccess(BaseConstant.IS_YESNO_NO);
                                result.setInfo("四要素信息校验未通过，请核查四要素" + "更新数据后校验结果" + chkRstCd);
                            }
                        }
                    } else {
                        // 开户失败
                        result.setSuccess(BaseConstant.IS_YESNO_NO);
                        result.setInfo(dataResultDTO.getInfo());
                    }
                } else {
                    // 开户失败
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("开户失败，请联系客户核实银行名称、银行卡、预留手机号等信息");
                }
            } else {
                BaseLogUtils.info(logger, "saveForZgcbank", "中关村银行已开户，不保存信息");
                result.setInfo("中关村银行已开户");
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "saveForZgcbank", "中关村银行开户保存失败 " + ex.getMessage());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("保存失败!");
            BaseLogUtils.error(logger, "saveForZgcbank", "中关村银行开户保存失败, 系统异常 " + ex.getMessage());
        }

        return result;
    }
}
